package com.lineage.data.item_etcitem.add;

import com.lineage.config.Configtype;
import com.lineage.data.cmd.EnchantArmor;
import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;

public class Zel100_ScrollEnchantArmor extends ItemExecutor {
  public static ItemExecutor get() {
    return new Zel100_ScrollEnchantArmor();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    int targObjId = data[0];
    L1ItemInstance tgItem = pc.getInventory().getItem(targObjId);
    if (tgItem == null)
      return; 
    boolean isErr = false;
    int safe_enchant = tgItem.getItem().get_safeenchant();
    int use_type = tgItem.getItem().getUseType();
    switch (use_type) {
      case 2:
      case 18:
      case 19:
      case 20:
      case 21:
      case 22:
      case 25:
      case 47:
        if (safe_enchant < 0)
          isErr = true; 
        break;
      default:
        isErr = true;
        break;
    } 
    if (tgItem.getBless() >= 128)
      isErr = true; 
    if (isErr) {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
      return;
    } 
    if (tgItem.getEnchantLevel() < Configtype.armorlv) {
      pc.getInventory().removeItem(item, 1L);
      EnchantArmor enchantArmor = new EnchantArmor();
      int randomELevel = enchantArmor.randomELevel(tgItem, item.getBless());
      enchantArmor.successEnchant(pc, tgItem, randomELevel);
    } else {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage("已达到防具最高强化阶段。"));
    } 
  }
}
